

class Solution(object):
    def divide(self, dividend, divisor):
        """
        :type dividend: int
        :type divisor: int
        :rtype: int
        """
        # i = 0
        # num = 0
        # if divisor > 0 and dividend >= 0:
        #     while num + divisor <= dividend:
        #         num += divisor
        #         i += 1
        #     print(i)
        # elif dividend < 0 and divisor < 0:
        #     divisor = -divisor
        #     dividend = -dividend
        #     while num + divisor <= dividend:
        #         num += divisor
        #         i += 1
        #     print(i)
        # else:
        #     if dividend >= 0:
        #         divisor = -divisor
        #         while num + divisor <= dividend:
        #             num += divisor
        #             i += 1
        #         print(-i)
        #     else:
        #         dividend = -dividend
        #         while num + divisor <= dividend:
        #             num += divisor
        #             i += 1
        #         print(-i)
        sign = -1 if dividend*divisor<0 else 1
        result = abs(dividend)//abs(divisor)
        result = sign*result
        if result > 2**31-1:
            return 2**31-1
        elif result < -2**31:
            return -2**31
        else:
            return result


if __name__ == '__main__':
    sol = Solution()
    sol.divide(-214, -1)

